﻿<%@ Control Language="C#" Inherits="Natrue.Web.MVC.AuthViewUserControl" %>
<%@ Import Namespace="Natrue.Data"%>
<%@ Import Namespace="CostTrade.BusinessLayer" %>

<div class="EdiDialogFill">
        <div id='gpMissionView' name='groupPanel'>
        
<table cellpadding="0" cellspacing="1" border="0" class="EdiDialogTable">
    <tr>
        <td>选择商品</td>
    </tr>
    <tr>
    <td>
        <table cellpadding="0" cellspacing="1" border="0" class="EdiDialogTable">
            <tr >
                <td class="grayTd" width="20%">商品分类</td>
                <td class="whiteTd" width="20%"><%=BuildWaresRootSelect() %></td>
                <td class="grayTd" width="20%">商品名称</td>
                <td class="whiteTd" width="40%" colspan="2"><input type="text" id="txtWareName" onchange="GetSelectData();" value="AAAAAAAAA" style="width:98%;"  /> </td>
            </tr>
            <%--<tr id="trEmpty"><td class="whiteTd colspan="5"></td></tr>--%>
            <tr>
                <td class="whiteTd" width="20%"><input type="checkbox" onclick="selectAll(this);" value="" />选全</td>
                <td class="whiteTd" width="80%" colspan="4" align="right">搜索结果：共搜索到 20 个商品</td>
            </tr>
            <tbody id="warebody">
            <tr>
                <td class="grayTd"><img  src="" style="width:170px; height:120px;"/><br /><input type="checkbox" name="warePrimarykey" value="" />选定</td>
                <td class="whiteTd" width="80%" colspan="4">
                    <table cellpadding="0" cellspacing="1" border="0" class="EdiDialogTable">
                        <tr>
                            <td class="grayTd" width="15%">商品编号</td>
                            <td class="whiteTd" width="35%"></td>
                            <td class="grayTd" width="15%">材料质地</td>
                            <td class="whiteTd" width="35%"></td>
                        </tr>
                        <tr>
                            <td class="grayTd" width="15%">条形码</td>
                            <td class="whiteTd" width="35%"></td>
                            <td class="grayTd" width="15%">毛重</td>
                            <td class="whiteTd" width="35%"></td>
                        </tr>
                        <tr>
                            <td class="grayTd" width="15%">商品中文名</td>
                            <td class="whiteTd" width="35%"></td>
                            <td class="grayTd" width="15%">厂家型号</td>
                            <td class="whiteTd" width="35%"></td>
                        </tr>
                        <tr>
                            <td class="grayTd" width="15%">商品西文名</td>
                            <td class="whiteTd" width="35%"></td>
                            <td class="grayTd" width="15%">规格型号</td>
                            <td class="whiteTd" width="35%"></td>
                        </tr>
                        <tr>
                            <td class="grayTd" width="15%">商品介绍</td>
                            <td class="whiteTd" width="85%" colspan="3">
                                <br />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            </tbody>
        </table>
    
    </td>
    </tr>
</table>

</div>
</div>
<link href="/Scripts/JQPlugs/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/JQPlugs/jquery.autocomplete.min.js" type="text/javascript"></script>
<script src="/Scripts/JQPlugs/jquery.bgiframe.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">

    $(document).ready(function() {
        //$("#txtWareName").autocomplete("/WaresLibrary/GetWareResults", { input: $("#txtWareName").val() + "|" + $("#seleWareCategory").val(), roundKey: Math.random() }).result(function() { });
});

function GetSelectData() {
    $.get("/WaresLibrary/GetWareResults", { name: $("#txtWareName").val(), category: ("#seleWareCategory").val(), reget: Math.random() }, function(result) {
        $("#warebody").append(result);
        loadImages();
    })
}
    
    //清理产品显示区域 
    function clearBbody(id) {
        $("#" + id + " tr").remove();
    }
    
    //选择所有
    function selectAll(obj) {
        $("input[type=checkbox][name=warePrimarykey]").attr("checked", obj.checked);
    }
    
    //
    function loadImages() {
        $("img").attr("src", "d:\\My Documents\\My Pictures\\韶关夜景.jpg");
        hasSelectWare();
    }
    
    //选择商品
    function selectWares() {
    
    }
    
    //移除已选商品
    function removeWares() {

    }

    function hasSelectWare() {
        $("input[type=hidden][pk=true]").each(function(i, o) {
            var ware = $("input[type=checkbox][name=warePrimarykey][value=" + o.value + "]");
            if (ware != undefined || ware != null) ware.remove();
        });
        
    }

</script>

<script type="text/C#" runat="server">
    
    private string BuildWaresRootSelect()
    {
        IActiveRecordHelper helper = ProxyContainer.FindLocalProxy<IActiveRecordHelper>();
        string sele = "<select id=\"seleWareCategory\"><option selected=\"selected\" value=\""+Guid.Empty+"\">---请选择---</option>{0}</select>";
        string reval = "";
        IList<WaresCategory> categoryRoots = helper.GetIBOList<WaresCategory>(NHibernate.Expression.Expression.Eq("ParentGuid", Guid.Empty));
        foreach (WaresCategory wares in categoryRoots)
            reval += BuildItems(wares, String.Empty);
        return String.Format(sele, reval);
    }

    private string BuildItems(WaresCategory parent, string flow)
    {
        IActiveRecordHelper helper = ProxyContainer.FindLocalProxy<IActiveRecordHelper>();
        string reVal = String.Format("<option value=\"{0}\">{1}</option>", parent.PrimaryKey, flow +"["+ parent.ChineseName+"-"+parent.EnglishName+"]");

        IList<WaresCategory> categoryChilds = helper.GetIBOList<WaresCategory>(NHibernate.Expression.Expression.Eq("ParentGuid",parent.PrimaryKey));
        foreach (WaresCategory child in categoryChilds)
            reVal += BuildItems(child, flow + "  ┣");
        return reVal;
    }

    
</script>